package com.company.gxcpc2020;

import java.util.Scanner;
import java.util.stream.Stream;

public class GxcpcH {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            sc.nextLine();
            char[][] map = Stream.generate(sc::nextLine).limit(7).map(String::toCharArray).toArray(char[][]::new);
            int num = 0;
            for (int i = 0; i < n; i++) {
                int x = i * 7;
                if (map[2][x + 3] == '#') {
                    num++;
                } else if ((map[2][x + 4] == '#') && (map[2][x + 5] == '.')) {
                    num += 2;
                } else if (map[3][x + 3] == '#' && map[1][x + 1] == '.') {
                    num += 3;
                } else if (map[3][x + 3] == '.' && map[2][x + 2] == '#') {
                    num += 4;
                } else if (map[3][x + 3] == '#' && map[1][1] == '#') {
                    num += 5;
                } else {
                    num += 6;
                }
            }
            System.out.println(num);
        }
    }
}
